/*
 * Project it.battlehorse.rcp.tools
 * Created on Nov 18, 2005
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */
package it.battlehorse.rcp.tools.log.actions;

import it.battlehorse.rcp.tools.log.ILoggable;
import it.battlehorse.rcp.tools.log.LogActivator;
import it.battlehorse.rcp.tools.log.dialogs.LogItemDialog;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;

/**
 * The Action which shows the details of the currently selected log item.
 * This action responds also to double-click events on the log item
 * 
 * @author battlehorse
 * @since Nov 27, 2005
 */
public class ShowLogDetailAction extends Action implements IDoubleClickListener {
	
	private TableViewer viewer;
	
	/**
	 * Creates a new istance of the class
	 * 
	 * @param viewer a reference to the tableViewer this dialog loads items from
	 */
	public ShowLogDetailAction(TableViewer viewer) {
		this.viewer = viewer;
		
		super.setText("&Show current item details");
		super.setImageDescriptor(LogActivator.getImageDescriptor("resources/detail.png"));
		super.setToolTipText("Show current item details");
	}
	
	@Override
	public void run() {
		IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
		if (sel != null && sel.getFirstElement() != null) {
			
			TitleAreaDialog dialog = new LogItemDialog((ILoggable) sel.getFirstElement());
			dialog.open();
			
		}
		
	}
	
	public void doubleClick(DoubleClickEvent event) {
		run();
	}

}
